package org.saxion.saktiehuis.service;

import java.util.List;

import org.saxion.saktiehuis.dao.GenericDao;
import org.saxion.saktiehuis.model.Product;
import org.saxion.saktiehuis.model.ProductCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class ProductService {
	@Autowired
	private GenericDao<Product, Long> productDao;
	@Autowired
	private ProductCategoryService productCategoryService;

	public ProductService() {
		super();
	}

	public List<Product> getAllProducts() {
		return productDao.findAll();
	}

	public List<Product> getProductsByCategoryId(Long id) {
		ProductCategory category = productCategoryService
				.getProductCategoryById(id);
		return productDao.findAllByProperty("category", category);
	}

	public Object getProductById(Long id) {
		return productDao.findById(id);

	}
}
